//
//  RootViewController.m
//  vnex
//
//  Created by sieg on 8/26/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"
#import "RSSReaderViewController.h"

@implementation RootViewController

@synthesize listOfRSS;

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];

    listOfRSS = [[NSMutableArray alloc] init];
	[listOfRSS addObject:[NSArray arrayWithObjects:@"Trang chủ",@"http://vnexpress.net/rss/gl/trang-chu.rss",nil]];
	[listOfRSS addObject:[NSArray arrayWithObjects:@"Xã hội",@"http://vnexpress.net/rss/gl/xa-hoi.rss",nil]];
	
	self.navigationItem.title = @"vnExpress";
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations.
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [listOfRSS count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	// Configure the cell.
	NSArray *cellRSS = [listOfRSS objectAtIndex:indexPath.row];
	cell.textLabel.text = [cellRSS objectAtIndex:0];
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	
    return cell;
}


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
	
	RSSReaderViewController *rssViewController = [[RSSReaderViewController alloc] 
												  initWithNibName:@"RSSReaderViewController" 
												  bundle:nil];
	rssViewController.selectRSSItemTitle = [[listOfRSS objectAtIndex:indexPath.row] objectAtIndex:0];
	rssViewController.selectRSSItemURL = [[listOfRSS objectAtIndex:indexPath.row] objectAtIndex:1];

	[self.navigationController pushViewController:rssViewController animated:YES];
	[rssViewController release];
	rssViewController = nil;
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
}


- (void)dealloc {
	[listOfRSS release];
    [super dealloc];
}

@end

